package search.service.impl;

import java.util.ArrayList;
import java.util.List;

import search.pojo.Areas;
import search.pojo.dao.AreasDao;
import search.pojo.dao.impl.AreasDaoImpl;
import search.service.AreasDaoManager;
import search.util.JsonUtil;

public class AreasDaoManagerImpl implements AreasDaoManager {

	private AreasDao areasDao;
	
	public AreasDaoManagerImpl() {
		areasDao = new AreasDaoImpl();
	}

	@Override
	public List<Areas> find(String inputArea) {
		return areasDao.find(inputArea);
	}

	@Override
	public String toJsonArray(String inputArea) {
		List<Areas> areasList = new ArrayList<>();
		String areasStr = " ";
		
		if(inputArea != null && !"".equals(inputArea.trim()))
			areasList = this.find(inputArea);
		else
			return areasStr;
		areasStr = "[";
		for(int i=0; i<areasList.size();i++)
		{
			if(i>4)
				break;
			if(i != areasList.size()-1&&i<4)
				areasStr += JsonUtil.toJsonString(areasList.get(i)) + ",";
			else 
				areasStr += JsonUtil.toJsonString(areasList.get(i));
		}
		areasStr += "]";
		return areasStr;	
	}

}
